<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/16/016
 * Time: 22:51
 */

namespace app\api\controller\v1;


use cmf\controller\HomeBaseController;
use think\Db;
use think\Loader;
use think\Validate;

/**
 * Class LiuyanController 留言控制器
 * @package app\api\controller\v1
 */
class LiuyanController extends HomeBaseController
{
    public function getPostData()
    {
        $data = [];
        !is_null(input('post.country')) && $data['country'] = input('post.country');
        !is_null(input('post.province')) && $data['province'] = input('post.province');
        !is_null(input('post.city')) && $data['city'] = input('post.city');
        !is_null(input('post.name')) && $data['name'] = input('post.name');
        !is_null(input('post.mobile')) && $data['mobile'] = input('post.mobile');
        !is_null(input('post.content')) && $data['content'] = htmlspecialchars(input('post.content'));
        $data['create_time'] = time();
        $validate = Loader::validate('Liuyan');
        if(!$validate->check($data)){
           return json([
               'code' => 0,
               'done' => false,
               'errorCode' => 3000,
               'msg' => $validate->getError()
           ]);
        }
        $result = Db::name('Liuyan')->insert($data);
        if ( $result ){
            return json([
                'code'=>1,
                'done' => true,
                'msg' => '提交成功!'
            ]);
        }
    }
}